

function say() {
    alert("299. 猜数字游戏");
}
say();

/**
 * @param {string} secret
 * @param {string} guess
 * @return {string}
 */
var getHint = function(secret, guess) {
    //10:52-11:07
    //公牛找出来简单,删除公牛元素
    //生成频率字典,比较两个频率字典
    var aCount = 0
    for(var i = secret.length - 1; i >= 0; i--){
        var sStr = secret.charAt(i)
        var gStr = guess.charAt(i)

        if(sStr == gStr){
            aCount++
             secret = secret.substring(0,i) + secret.substring(i + 1)
             guess = guess.substring(0,i) + guess.substring(i + 1)
        }
    }

    var sDic = {}
    var gDic = {}
    for(var i = 0; i < secret.length; i++){
        if(!sDic[secret.charAt(i)]) {
            sDic[secret.charAt(i)] = 0
        }
        sDic[secret.charAt(i)]++
    }

    for(var i = 0; i < guess.length; i++){
        if(!gDic[guess.charAt(i)]) {
            gDic[guess.charAt(i)] = 0
        }
        gDic[guess.charAt(i)]++
    }

    var bCount = 0
    for(var key in sDic){
        var val = sDic[key]
        if(gDic[key]) {
            bCount += Math.min(val, gDic[key])
        }
    }
    return aCount + 'A' + bCount + 'B'
};
